package com.moon.game.command.guest.gift;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.constants.ErrorCode;
import com.moon.game.exception.GException;
import com.moon.game.manager.GiftMG;
import com.moon.game.resource.model.Gift;
import com.moon.game.service.GiftService;
import com.moon.game.vos.ErrorMsg;

/**
 * @description 查看礼包
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-8-8 下午4:43:32
 */
public class ViewGiftCmd extends BaseCmd {

	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
			case STATU_INIT:
				doInit(req);
				break;
			case STATU_CHECK:
				doCheckSelf(req);
				break;
			case STATU_RETURN:
				doResponse(req);
				break;
			default:
				break;
		}
	}

	@Override
	protected void doResponse(RequestSession req) throws GException {
		String[] ps = req.getClientRequest().getPs();
		if (ps == null) {
			doResponsePsError(req);
			return;
		}
		Integer giftId = Integer.parseInt(ps[0]);
		if (giftId == null) {
			doResponsePsError(req);
			return;
		}
		
		Gift gift = GiftMG.instance.getGiftById(giftId);
		if (gift == null) {
			doResponseErrorMsg(req, ErrorMsg.build(ErrorCode.ERR_RESOURCE,"没有你要找的礼包资源"));
			return;
		}
		
		req.setVO("has_the_gift", GiftService.checkGift(req.getPlayer(), giftId));
			
		req.setVO("gift_id", giftId);
		response(req, req.getClientResponse());
	}

}
